<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" import="java.util.Map,java.util.List,com.wit.dao.impl.EmployeeDaoImpl,com.wit.po.Clientlevel,com.wit.dao.impl.ClientlevelDaoImpl" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>客户列表</title>
<link href="<%=basePath%>/style/main.css" rel="stylesheet" type="text/css" />
<link type="text/css" rel="stylesheet" href="<%=basePath%>/style/style.css" />

<%@ taglib prefix="s" uri="/struts-tags" %>

<script>
	function inportExcel()
    {
   		 window.location.href="importClient.jsp";
    }
    
	function changeV(objID)
	{
		if(document.getElementById("tbody_"+objID).style.display == "block")
		{
			
			document.getElementById("img_"+objID).src = "<%=basePath%>/images/ico_have2.gif";
			document.getElementById("tbody_"+objID).style.display = "none"
		}
		else
		{
			document.getElementById("img_"+objID).src = "<%=basePath%>/images/ico_nohave2.gif";
			document.getElementById("tbody_"+objID).style.display = "block"
		}
	}
	function submitForm()
	{
		searchClientForm.submit();
	}
	function resetForm()
	{
		searchClientForm.reset();
	}
	function gotoPage(page)
	{
		if(page == 0)
		{
			searchClientForm.pageNumber.value = document.getElementById("t_pageNumber").value;
			searchClientForm.pageSize.value = document.getElementById("t_pageSize").value;
		}
		else
		{
			searchClientForm.pageNumber.value = page;
		}
		searchClientForm.submit();
	}	
	function getTop(e){ 
		var offset=e.offsetTop; 
		if(e.offsetParent!=null) offset+=getTop(e.offsetParent); 
		return offset; 
	} 
	//获取元素的横坐标 
	function getLeft(e){ 
		var offset=e.offsetLeft; 
		if(e.offsetParent!=null) offset+=getLeft(e.offsetParent); 
		return offset; 
	}
	function showTree(e)
	{
		var top = getTop(e);
		var left = getLeft(e);
		var obj = document.getElementById("showTreeDiv");
		if(obj.innerHTML == null || obj.innerHTML.length <= 0)
			obj.innerHTML = "<html><iframe id=\"editIFrame\" frameborder=\"0\" src=\"area_select.jsp\" scrolling=\"yes\" width=\"300\" height=\"300\"></iframe></html>";
		obj.style.left=left;
		obj.style.top = top;
		obj.style.display="";
	}
	function startEdit()
	{
		var obj;
		var i = 0;
		while((obj = document.getElementById("chk"+i)) != null)
		{
			if(obj.checked)
			{
				document.location="clientInfo!startEdit?clientId="+obj.value;
				return;
			}
			i++;
		}
		alert("必须选择一个客户");
	}
	function removeClient()
	{
		var obj;
		var i = 0,counter = 0,id;
		while((obj = document.getElementById("chk"+i)) != null)
		{
			if(obj.checked)
			{
				id = obj.value;
				counter ++;
			}
			i++;
		}
		if(counter > 1)
			alert("每次只能删除一个客户信息");
		else if(counter == 1)
		{
			if(confirm("确定删除？") == true)
			{
				var number = searchClientForm.pageNumber.value;
				var size = searchClientForm.pageSize.value;
				document.location = "clientInfo!removeClient?clientId="+id+"&page.pageNumber="+number+"&page.pageSize="+size;
			}
		}
		else
			alert("必须选择一个客户");
	}
	
	    function AutomateExcel(){
                var curTbl = document.getElementById("ClientTable");
			    var oXL = new ActiveXObject("Excel.Application");
			    //创建AX对象excel
			    var oWB = oXL.Workbooks.Add();
			    //获取workbook对象
			    var oSheet = oWB.ActiveSheet;
			    //激活当前sheet
			    var Lenr = curTbl.rows.length;
			    //取得表格行数
			    for (i = 0; i <Lenr;i++)
			    {
			        var Lenc = curTbl.rows(i).cells.length;
			        //取得每行的列数
			        for (j = 0; j <Lenc;j++)
			        {
			            oSheet.Cells(i + 1, j + 1).value = curTbl.rows(i).cells(j).innerText;
			            //赋值
			        }
			    }
			    oXL.Visible = true;
			    //设置excel可见属性
            }
	
</script>

<%
	Map map = EmployeeDaoImpl.s_GetEmployeeNameList();
	List<Clientlevel> levelList = ClientlevelDaoImpl.s_GetClientlevelList();
	if(levelList == null || levelList.size() == 0)
	{
%>
<script type="text/javascript">
	alert("没有客户级别列表信息，请先添加");
	document.location = "clientlevel_new.jsp";
</script>
<%
		return;
	}
	Clientlevel allLevel = new Clientlevel();
	allLevel.setClientlevelId("");
	allLevel.setClmemo("--全部--");
	levelList.add(0,allLevel);
	
	map.put("","--全部--");
	request.setAttribute("levelList",levelList);
	request.setAttribute("employeeMap",map);
%>

</head>
<body>

<div id="showTreeDiv" style="display:none; position:absolute"></div>

<table width="1200" cellpadding="0" cellspacing="0" class="table">
  <tr>
    <td>
      <table width="100%"  cellpadding="0" cellspacing="0" class="table2">
        <tr>
          <td valign="top">
            <table width="100%" class="top" cellpadding="0" cellspacing="0">
              <tr>
                <td>当前位置:&nbsp;客户管理&nbsp;>>&nbsp;客户信息</td>
              </tr>
            </table>
			<div id="mainareacontent">
        <div class="mainarea">
            <div class="search">
			  <s:form name="searchClientForm" id="searchClientForm" action="clientInfo!searchClient" method="post" theme="simple">
                <table width="100%" cellpadding="0" cellspacing="0">
                    <tr>
                        <td class="ico">
                            <a href="javascript:changeV(1)">
                                <img  src="<%=basePath%>/images/ico_have2.gif" id="img_1" border="0" />
                            </a>
                        </td>
                        <td >
                          <table cellpadding="0" cellspacing="0" width="100%" >
                            <tr>
                              <th width="7%">客户编号：</th>
                              <td width="34%">
                                <s:textfield name="client.clientId"></s:textfield>
                              </td>
                              <th width="8%">客户名称：</th>
                              <td width="23%">
                            	<s:textfield name="client.clientName"></s:textfield>
                              </td>
                              <td width="28%" align="left" >
                                  <a href="javascript:void(0);" onclick="javascript:submitForm();">
                                  	<img src="<%=basePath%>/images/btn_search.gif" />&nbsp;
                                  </a>
                                  <a href="javascript:void(0);" onclick="javascript:resetForm();">
                                  	<img src="<%=basePath%>/images/btn_reset.gif" />
                                  </a>
                              </td>
                              </tr>
                                <tbody id="tbody_1" style="display: none; border: 0px;">
                                    <tr>
                                      <th height="19"> 客户类别：</th>
                                      <td>
                                      	<s:select list="#{'':'--全部--','个人':'个人','团体':'团体'}" 
                                      		name="client.clientType" listKey="key" listValue="value">
                                        </s:select>
                                      </td>
                                      <th>手机：</th>
                                      <td>
                            			<s:textfield name="client.clientPhone"></s:textfield>
                                      </td>
                                      <td>&nbsp;</td>
                                    </tr>
                                    <tr>
                                        <th>所属地区：</th>
                                        <td>
                            				<s:textfield onclick="javascript:showTree(this);" id="areaId" name="client.area.areaId"></s:textfield>
                                        </td>
                                       
                                         <th>客户电话：</th>
                                        <td>
                                        	<s:textfield name="client.clienttelephone"></s:textfield>
                                        </td>
                                        <td>&nbsp;</td>
                                    </tr>
                                    
                                    <tr>
                                        <th height="19">客户级别：</th>
                                        <td>
					                   		<s:select name="client.clientlevel.clientlevelId" 
					                   					list="#request.levelList" listKey="clientlevelId" listValue="%{clientlevelId+'--'+clmemo}" >
					                   		</s:select>
                                        </td>
                                        <th>身份证/注册号：</th>
                                        <td>
                                        	<s:textfield name="client.clientIdcard"></s:textfield>
                                        </td>
                                        
                                        <td>&nbsp;</td>
                                    </tr>
                                    <tr>
                                          <th>业 务 员： </th>
                                          <td>
					                      	  <s:select name="client.employee.employeeId" 
					                      	  				list="#request.employeeMap" listKey="key" listValue="value">
					                      	  </s:select>
                                          </td>
                                      <th>行业类型：</th>
                                      <td>
										<s:select name="client.clientIndustry" 
												list="{'金融','服务','地产','保险'}"
												listKey="key" listValue="value">
										</s:select>
                                      </td>
                                      <td>&nbsp;</td>
                                    </tr>
                                </tbody>
                      		</table>
                      </td>
                    </tr>
                </table>
                
                <s:hidden id="pageNumber" name="page.pageNumber"></s:hidden>
                <s:hidden id="pageSize" name="page.pageSize"></s:hidden>
              </s:form>
            </div>
            
                    <table width="100%" cellpadding="0" cellspacing="0"class="table3">
                        <tr>
                            <td width="6%" class="title">&nbsp;</td>
                            <td width="5%" ><span class="clientinfo_but" >
                            	<a href="clientinfo_new.jsp" target="_self">新&nbsp;增</a></span>
                            </td>
                            <td width="5%" >
                            	<span class="clientinfo_but"><a onclick="javascript:startEdit();" href="javascript:void(0);" target="_self">修&nbsp;改</a></span>
                            </td>
                            <td width="5%" >
                            	<a onclick="javascript:removeClient();" href="javascript:void(0);" target="_self">
                            		<img src="<%=basePath%>/images/btn_del.gif" alt="3" />
                            	</a>
                            </td>
                            <td width="5%" >
                            	<img src="<%=basePath%>/images/btn_refresh.gif" alt="3" width="50" height="20" />
                            </td>
                            <td width="18%" >&nbsp;</td>
                            <td width="5%" ><span class="clientinfo_but" onclick="inportExcel()">导&nbsp;入</span></td>
                            <td width="5%" ><span class="clientinfo_but" onclick="AutomateExcel()">导&nbsp;出</span></td>
                          
                            <td width="5%" ><span class="clientinfo_but">打&nbsp;印</span></td>  
                            <td width="14%" >&nbsp;</td>
                        </tr>
                    </table>

            <table width="100%" cellpadding="0" cellspacing="1" class="dg_borderstyle" id="ClientTable">
              <thead>
                <tr>
                  <th width="26" height="31"> <input type="checkbox" onclick="docheck()" id="chk_all" /></th>
                  <th width="98">客户编号</th>
                  <th width="100">客户名称</th>
                  <th width="194">身份证/营业执照注册号</th>
                  <th width="70">客户级别</th>
                  <th width="56">联系人</th>
                  <th width="121">手机</th>
                  <th width="194">客户电话</th>
                  <th width="120">业务员</th>
                  <th width="81">登记时间</th>
                  <th width="75">客户类别</th>
                </tr>
              </thead>
              <tbody >
              	<s:iterator value="#request.clientList" status="st" id="clientList">
                <tr>
                  <td>
                  	<s:checkbox name="chks" id="%{'chk'+#st.getIndex()}" fieldValue="%{clientId}" theme="simple" />
                  </td>
                  <td>
                	<a href="clientInfo!showClientInfo?clientId=<s:property value='clientId'/>" >
                		<s:property value="clientId"/>
                	</a>
                  </td>
                  <td>
                  	<a href="clientInfo!showClientInfo?clientId=<s:property value='clientId'/>" >
                  		<s:property value="clientName"/>
                  	</a>
                  </td>
                  <td>
                  	<s:property value="clientIdcard"/>
                  </td>
                  <td>
                  	<s:property value="clientlevel.clientlevelId"/>
                  </td>
                  <td></td>
                  <td>
                  	<s:property value="clientPhone"/>
				  </td>
                  <td>
                  	<s:property value="clienttelephone"/>
                  </td>
                  <td>
                  	<s:property value="%{employee.employeeId+'-'+#request.employeeMap.get(employee.employeeId)}"/>
                  </td>
                  <td>
                  	<s:date name="recordTime" format="yyyy-MM-dd"/>
                  </td>
                  <td>
                  	<s:property value="clientType"/>
                  </td>
                </tr>
              	</s:iterator>
              </tbody>
            </table>

            <table width="100%" cellpadding="0" cellspacing="0" class="dg_pagestyle">
                <tr>
                    <td class="pageinfo">
                        	第<s:property value="page.pageNumber"/>页 | 共<s:property value="page.totalPage"/>页
                    </td>
                    <td class="pagebutton">
                        每页
                        <s:select id="t_pageSize" name="page.pageSize" list="{'10','20','30','40','50'}" theme="simple">
                        </s:select>
                        条记录 | 第
                        <s:textfield id="t_pageNumber" name="page.pageNumber" cssStyle="width: 20px;" theme="simple" />
                        页
                        <a onclick="javascript:gotoPage(0);" href="javascript:void(0);">
                        	<img src="<%=basePath%>/images/btn_go.gif" />
                        </a>
                        <a onclick="javascript:gotoPage(1);" href="javascript:void(0);">
                        	<img src="<%=basePath%>/images/btn_sy.gif" width="55" height="20" />
                        </a>
                        <a onclick="javascript:gotoPage(<s:property value='page.prePage' />);" 
                        		href="javascript:void(0);">
                        	<img src="<%=basePath%>/images/btn_syy.gif" width="55" height="20" />
                        </a>
                        <a onclick="javascript:gotoPage(<s:property value='page.nextPage' />);" 
                        		href="javascript:void(0);">
                        	<img src="<%=basePath%>/images/btn_xyy.gif" width="55" height="20" />
                        </a>
                        <a onclick="javascript:gotoPage(<s:property value='page.lastPage' />);" 
                        		href="javascript:void(0);">
                        	<img src="<%=basePath%>/images/btn_wy.gif" width="55" height="20" />
                        </a>
                    </td>
                </tr>
            </table>
        </div>
      </div>
		  </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
</body>
</html>
